package fudan.se.lab2.controller;

import fudan.se.lab2.controller.request.ApplyRequest;
import fudan.se.lab2.controller.request.OpenPostRequest;
import fudan.se.lab2.domain.Meeting;
import fudan.se.lab2.domain.Post;
import fudan.se.lab2.service.ChairService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class ChairController {
    private final ChairService chairService;

    @Autowired
    public ChairController(ChairService chairService) {
        this.chairService = chairService;
    }

    @PostMapping("/meeting")
    public ResponseEntity<Meeting> apply(@RequestBody ApplyRequest request) {
        return ResponseEntity.ok(chairService.apply(request));
    }

    @PostMapping("/allowContribute")
    public ResponseEntity<Meeting> allowContribute(@RequestBody String meetingFullName) {
        return ResponseEntity.ok(chairService.allowContribute(meetingFullName));
    }

    @PostMapping("/openReview")
    public ResponseEntity<Boolean> openReview(@RequestBody String meetingFullName) {
        return ResponseEntity.ok(chairService.openReview(meetingFullName));
    }

    @PostMapping("/closeReview")
    public ResponseEntity<Boolean> closeReview(@RequestBody String meetingFullName) {
        return ResponseEntity.ok(chairService.closeReview(meetingFullName));
    }

    @PostMapping("/showSecondResult")
    public ResponseEntity<Boolean> showSecondResult(@RequestBody String meetingFullName) {
        return ResponseEntity.ok(chairService.showSecondResult(meetingFullName));
    }

    @PostMapping("/closeFirstPost")
    public ResponseEntity<Post> closeFirstPost(@RequestBody OpenPostRequest request){
        return ResponseEntity.ok(chairService.closeFirstPost(request.getMeetingFullName(),request.getTitle()));
    }

    @PostMapping("/closeSecondPost")
    public ResponseEntity<Post> closeSecondPost(@RequestBody OpenPostRequest request){
        return ResponseEntity.ok(chairService.closeSecondPost(request.getMeetingFullName(),request.getTitle()));
    }
}
